Micron Document
🎖️GitЯра🎖️


Displaying Raw • Download

core/navigation/src/commonMain/kotlin/org/meshtastic/core/navigation/NavBackStackExt.kt 1390a3cd4f7bc55a37433d1d868e65c01678eb31 (1390a3cd) Text, 1.78 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.navigation

Tff7b72import T7ee787androidx.navigation3.runtime.NavKey

T8b949e/**
* Replaces the last entry in the back stack with the given route. If the back stack is empty, it simply adds the route.
*/
Tff7b72fun Td2a8ffMutableListTff7b72<Te6edf3NavKeyTff7b72>Tb4b4b4.Te6edf3replaceLastTb4b4b4(Te6edf3routeTb4b4b4: Te6edf3NavKeyTb4b4b4) Tb4b4b4{
Tff7b72if Tb4b4b4(Te6edf3isNotEmptyTb4b4b4(Tb4b4b4)Tb4b4b4) Tb4b4b4{
Tff7b72if Tb4b4b4(Tff7b72thisTff7b72[Te6edf3lastIndexTff7b72] Tff7b72!Tff7b72= Te6edf3routeTb4b4b4) Tb4b4b4{
Tff7b72thisTff7b72[Te6edf3lastIndexTff7b72] Tff7b72= Te6edf3route
Tb4b4b4}
Tb4b4b4} Tff7b72else Tb4b4b4{
Te6edf3addTb4b4b4(Te6edf3routeTb4b4b4)
Tb4b4b4}
Tb4b4b4}

T8b949e/**
* Replaces the entire back stack with the given routes in a way that minimizes structural changes and prevents the back
* stack from temporarily becoming empty.
*/
Tff7b72fun Td2a8ffMutableListTff7b72<Te6edf3NavKeyTff7b72>Tb4b4b4.Te6edf3replaceAllTb4b4b4(Te6edf3routesTb4b4b4: Te6edf3ListTff7b72<Te6edf3NavKeyTff7b72>Tb4b4b4) Tb4b4b4{
Tff7b72if Tb4b4b4(Te6edf3routesTb4b4b4.Te6edf3isEmptyTb4b4b4(Tb4b4b4)Tb4b4b4) Tb4b4b4{
Te6edf3clearTb4b4b4(Tb4b4b4)
Tff7b72return
Tb4b4b4}
Tff7b72for Tb4b4b4(Te6edf3i Tff7b72in Te6edf3routesTb4b4b4.Te6edf3indicesTb4b4b4) Tb4b4b4{
Tff7b72if Tb4b4b4(Te6edf3i Tff7b72< Te6edf3sizeTb4b4b4) Tb4b4b4{
T8b949e// Only mutate if the route actually changed, protecting Nav3's internal state matching.
Tff7b72if Tb4b4b4(Tff7b72thisTff7b72[Te6edf3iTff7b72] Tff7b72!Tff7b72= Te6edf3routesTff7b72[Te6edf3iTff7b72]Tb4b4b4) Tb4b4b4{
Tff7b72thisTff7b72[Te6edf3iTff7b72] Tff7b72= Te6edf3routesTff7b72[Te6edf3iTff7b72]
Tb4b4b4}
Tb4b4b4} Tff7b72else Tb4b4b4{
Te6edf3addTb4b4b4(Te6edf3routesTff7b72[Te6edf3iTff7b72]Tb4b4b4)
Tb4b4b4}
Tb4b4b4}
Tff7b72while Tb4b4b4(Te6edf3size Tff7b72> Te6edf3routesTb4b4b4.Te6edf3sizeTb4b4b4) Tb4b4b4{
Te6edf3removeAtTb4b4b4(Te6edf3lastIndexTb4b4b4)
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.04s